<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    protected $table = 'movie_comments';
    protected $fillable = ['content', 'movie_id', 'user_id', 'comment_id', 'source', 'created_at'];
    public function movie()
    {
        return $this->belongsTo(Movie::class);
    }

    public function author()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function scopeRecent($query)
    {
        // 按照创建时间排序
        return $query->orderBy('created_at', 'desc');
    }
}
